package controllers

import (
	"encoding/json"
	"wego/models"
)

type AuthController struct {
	BaseController
}

//权限组列表
func (this *AuthController) AuthList() {
	params := models.GroupsQueryparam{}
	_ = json.Unmarshal(this.Ctx.Input.RequestBody, &params)
	list, count := models.AuthList(&params)
	result := models.ResultList{
		List:  list,
		Count: count,
	}
	this.JsonResult(1, "操作成功", &result)
}

//编辑权限组
func (this *AuthController) AuthSave() {
	params := models.AuthSaveParam{}
	_ = json.Unmarshal(this.Ctx.Input.RequestBody, &params)
	err := models.AuthSave(&params)
	if err == nil {
		this.JsonResult(1, "操作成功", "")
	} else {
		this.JsonResult(0, "操作失败", "")
	}
}

//更改权限组状态
func (this *AuthController) AuthStatus() {
	params := models.AuthGroup{}
	_ = json.Unmarshal(this.Ctx.Input.RequestBody, &params)
	err := models.AuthStatus(&params)
	if err == nil {
		this.JsonResult(1, "操作成功", "")
	} else {
		this.JsonResult(0, "操作失败", "")
	}
}

//删除权限组
func (this *AuthController) AuthDel() {
	params := models.AuthGroup{}
	_ = json.Unmarshal(this.Ctx.Input.RequestBody, &params)
	err := models.AuthDel(&params)
	if err == nil {
		this.JsonResult(1, "操作成功", "")
	} else {
		this.JsonResult(0, "操作失败", "")
	}
}

//从指定组中删除指定用户
func (this *AuthController) MemberDel() {
	params := models.GroupAccessDelParams{}
	_ = json.Unmarshal(this.Ctx.Input.RequestBody, &params)
	err := models.MemberDel(&params)
	if err == nil {
		this.JsonResult(1, "操作成功", "")
	} else {
		this.JsonResult(0, "操作失败", "")
	}
}

//权限组所有权限
func (this *AuthController) RuleList() {
	params := models.GroupIdParam{}
	_ = json.Unmarshal(this.Ctx.Input.RequestBody, &params)
	list := models.RuleList(params.GroupId)
	result := models.ResultList{
		List: list,
	}
	this.JsonResult(1, "操作成功", &result)
}
